package cn.wolfcode.wms.service.impl;

import cn.wolfcode.wms.domain.Brand;
import cn.wolfcode.wms.mapper.BrandMapper;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IBrandService;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements IBrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public void saveOrUpdate(Brand entity) {
        if (entity.getId() != null) {
            brandMapper.updateByPrimaryKey(entity);
        } else {
            brandMapper.insert(entity);
        }
    }

    @Override
    public void delete(Long id) {
        if (id != null) {

            brandMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public Brand get(Long id) {

            Brand entity = brandMapper.selectByPrimaryKey(id);
        return entity;

    }

    @Override
    public List<Brand> selectall() {
        List<Brand> depts = brandMapper.selectAll();
        return depts;
    }

    @Override
    public PageResult queryForList(QueryObject qo) {
        int rows = brandMapper.rows(qo);
        if (rows == 0) {
            return PageResult.EMPTY_RESULT;

        }
        PageResult result = new PageResult(qo.getCurrentPage(), qo.getPageSize(), rows, brandMapper.queryForList(qo));
        System.out.println(66);
        return result;

    }
}
